let gulp     = require("gulp"); // gulp是一个实例对象;
//插件的引入
let cleanCss = require("gulp-clean-css");
let rename   = require("gulp-rename");
let concat   = require("gulp-concat");
let babel    = require("gulp-babel");
let uglify   = require("gulp-uglify");
let dev      = require("./gulp.dev");
// var sass = require('gulp-sass');
// sass.compiler = require('node-sass');


// 外置paths => 因为方便配置;
let { paths }    = require("./gulp.config");

let type = process.argv[3] ? process.argv[3] : "dev"; // ???
//process 为全局变量不需要require
// 路径;
// 转存;
function styles(){
      return gulp.src(paths.styles.src) // gulp.src("路径")找到相应的文件 流buffer
            // .pipe(sass.on('error', sass.logError)) // .pipe()管子 , 在这里面对数据进行操作 , 操作数据源
            // .pipe(cleanCss())  //.pipe(其他插件) 使用其他插件对数据进行处理
            .pipe(gulp.dest(paths.styles.dist)) //转存操作
}
function scripts(){
      return gulp.src(paths.scripts.src)
            // .pipe(concat("index.js"))
            .pipe(babel({ //bable ES6 转 ES5
                  presets: ['@babel/env']
            }))
            .pipe(uglify())
            .pipe(gulp.dest(paths.scripts.dist))
}

function html(){
      return gulp.src(paths.html.src)
            .pipe(gulp.dest(paths.html.dist))
}


let build = gulp.series( html , styles , scripts ); //队列执行 gulp.series()

// 默认指令;
exports.build = build;
exports.dev = dev;



